<template>
  <div class="app-container">
    <el-card class="box-card">

      <div class="flex items-center flex-wrap">
        <el-date-picker
          v-model="date_value"
          class="mr-5"
          clearable
          end-placeholder="邀请结束时间"
          range-separator="-"
          start-placeholder="邀请开始时间"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          @change="handleChangeDate"
        >
        </el-date-picker>
        <el-button type="primary" @click="searchSubmit">查询</el-button>
        <el-button type="primary" @click="resetSubmit">重置</el-button>
      </div>

      <el-table
        ref="multipleTable"
        v-loading="loading"
        :data="tableData"
        border
        class="mt-3"
        stripe
        style="width: 100%"
        tooltip-effect="dark"
      >
        <el-table-column label="用户编号" prop="user_code"></el-table-column>
        <el-table-column label="用户昵称" prop="nickname"></el-table-column>
        <el-table-column label="审核状态" prop="audit_status">
          <template slot-scope="{row}">
            <span v-if="row.audit_status === 0">待审核</span>
            <span v-if="row.audit_status === 1">通过</span>
            <span v-if="row.audit_status === -1">拒绝</span>
          </template>
        </el-table-column>
        <el-table-column label="申请时间" prop="apply_time"></el-table-column>
        <el-table-column label="审核时间" prop="audit_time"></el-table-column>
        <el-table-column label="面试时间" prop="interview_start_at"></el-table-column>
        <el-table-column label="面试状态" prop="interview_status">
          <template v-if="row.audit_status === 1" slot-scope="{row}">
            <span v-if="row.interview_status === -1">拒绝</span>
            <span v-if="row.interview_status === 0">待面试</span>
            <span v-if="row.interview_status === 2">未面试</span>
          </template>
        </el-table-column>
        <el-table-column label="面试次数" prop="interview_count"></el-table-column>
        <el-table-column label="审核人" prop="audit_nickname"></el-table-column>
      </el-table>

      <!-- 分页 -->
      <cus-pagination
        v-show="listQuery.total > 0"
        :limit.sync="listQuery.perPage"
        :page.sync="listQuery.page"
        :total="listQuery.total"
        @pagination="getTableData"
      />


    </el-card>
  </div>
</template>

<script>
import { applyList } from '@/api/sys/anchorList'
import { InterviewList } from '@/api/anchorManagement/anchorInterviewSetting'

export default {
  name: 'qualification',
  components: {},
  data() {
    return {
      title: '',
      form: {
        session: ''
      },
      options1: [
        { label: '待审核', value: 0 },
        { label: '通过', value: 1 },
        { label: '拒绝', value: -1 }
      ],
      options2: [
        { label: '待面试', value: 0 },
        { label: '未面试', value: 2 },
        // { label: "通过", value: 1 },
        { label: '拒绝', value: -1 }
      ],
      options3: [],
      tableData: [],
      listQuery: {
        page: 1,
        perPage: 10,
        start_time: '',
        end_time: ''
      },
      rules: {
        session: [{ required: true, message: '请选择面试场次', trigger: 'blur' }]
      },
      loading: false,
      apply_id: undefined,
      date_value: ''
    }
  },
  created() {
    this.getTableData()
    this.getInterviewSession()
  },
  methods: {
    handleChangeDate(value) {
      if (value) {
        this.listQuery.start_time = value[0]
        this.listQuery.end_time = value[1]
      } else {
        this.listQuery.start_time = undefined
        this.listQuery.end_time = undefined
      }
    },

    // 网络请求
    /**
     * getTableData
     * @desc 获取表格数据
     */
    async getTableData() {

      this.loading = true
      for (let key in this.listQuery) {
        this.listQuery[key] = this.listQuery[key] === '' ? undefined : this.listQuery[key]
      }
      const detail = await applyList(this.listQuery)
      if (detail.code === 200) {
        this.tableData = detail.data.data
        this.listQuery.page = detail.data.current_page
        this.listQuery.total = detail.data.total
        this.listQuery.perPage = Number(detail.data.per_page)
        this.loading = false
      }
    },
    async getInterviewSession() {
      const detail = await InterviewList({
        perPage: 90000,
        is_now: 1
      })
      if (detail.code === 200) {
        this.options3 = detail.data.data
      }
    },
    closeDialog(form) {
      if (this.$refs[form]) {
        this.$refs[form].clearValidate() // 清除整个表单的校验
        this.$refs[form].resetFields() // 清除整个表单的校验
      }
    },
    searchSubmit() {
      this.listQuery.page = 1
      this.getTableData()
    },
    resetSubmit() {
      this.date_value = ''
      this.listQuery = {
        page: 1,
        perPage: 10,
        start_time: '',
        end_time: ''
      }
      this.getTableData()
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
